/**
 * 批注设置组件
 */
function scAnnotationSetting(){
    var com = scCommon.instance();
    var crEle = com.crEle;
    
    /**
     * 批注设置元素
     */
    var annotation = null;

    /**
     * 创建视图
     */
    this.createView = function(){
        annotation = crEle(null, "sc-annotation-setting");

        let label = crEle("label");
        label.innerText = "批注类型:";

        row = crEle(null, "sc-setting-row");
        row.appendChild(label);

        annotation.appendChild(row);

        var types = [
            {label: "提示", value:"info", checked: true},
            {label: "警告", value:"warning"},
            {label: "严重", value:"danger"},
        ];

        row = crEle(null, "sc-setting-row,sc-row-content");

        for(var i in types){
            let input = crEle("input");

            input.setAttribute("type", "radio");
            input.setAttribute("name", "type");

            input.value = types[i].value;
            input.checked = types[i].checked;

            label = crEle("label");
            label.innerText = types[i].label;

            label.prepend(input);
            row.appendChild(label);
        }

        annotation.appendChild(row);

        label = crEle("label");
        label.innerText = "输入批注内容:";

        row = crEle(null, "sc-setting-row");
        row.appendChild(label);
        annotation.appendChild(row);
        
        var textarea = crEle("textarea");
        textarea.setAttribute("name", "content");

        row = crEle(null, "sc-setting-row,sc-row-content");
        row.appendChild(textarea)
        annotation.appendChild(row);

        return annotation;
    }

    /**
     * 获取数据
     */
    this.getData = function(){
        var data = {};
        var elements = annotation.querySelectorAll("[name]");

        for(var i = 0; i < elements.length; i++){
            let element = elements[i];
            let name = element.getAttribute("name");
            let tagName = element.tagName.toLowerCase();

            if(tagName == "input"){
                let type = element.getAttribute("type");
                if(type == "checkbox"){
                    if(!element.checked) continue;
                    data[name] = data[name] ? data[name] : [];
                    data[name].push(element.value);
                }else if(type == "radio"){
                    if(!element.checked) continue;
                    data[name] = element.value;
                }else{
                    data[name] = element.value;
                }
            }else{
                data[name] = element.value;
            }
        }

        return data;
    }
}